<template>
    <div class="page-container">
        <div>
            <div class="operation-container">
                <el-button type="primary" @click="onPrint">打印</el-button>
            </div>
            <div id="deviceDispatchPrint" class="print-container">
                <div class="print-title">耗材申请单</div>
                <table class="table-class" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td class="print-label">项目编码</td>
                        <td class="print-input-content2">
                            {{ form.projectCode }}
                        </td>
                        <td class="print-label">项目名称</td>
                        <td class="print-input-content2">
                            {{ form.projectName }}
                        </td>
                    </tr>
                    <tr>
                        <td class="print-label">部门名称</td>
                        <td class="print-input-content2">
                            {{ form.departmentName }}
                        </td>
                        <td class="print-label">申请单类型</td>
                        <td class="print-input-content2">
                            {{ form.category == 1 ? '办公耗材' : '生产耗材' }}
                        </td>
                    </tr>
                    <tr>
                        <td class="print-label">收货人</td>
                        <td class="print-input-content2">
                            {{ form.consignee }}
                        </td>
                        <td class="print-label">联系电话</td>
                        <td class="print-input-content2">
                            {{ form.phone }}
                        </td>
                    </tr>
                    <tr>
                        <td class="print-label">收货地址</td>
                        <td class="print-input-content" colspan="3">
                            {{ form.address }}
                        </td>
                    </tr>
                    <tr>
                        <td class="print-label">项目组人数</td>
                        <td class="print-input-content2">
                            {{ form.toll }}
                        </td>
                        <td class="print-label">耗材总价（元）</td>
                        <td class="print-input-content2">
                            {{ form.totalPrice == null ? '' : form.totalPrice / 100 }}
                        </td>
                    </tr>
                    <tr>
                        <td class="print-label">其他说明</td>
                        <td class="print-input-content" colspan="3">
                            {{ form.remark }}
                        </td>
                    </tr>
                    <tr>
                        <td class="print-label-line" colspan="4">耗材列表</td>
                    </tr>
                    <tr>
                        <td class="print-table-line" colspan="4">
                            <table border="0" cellspacing="0" cellpadding="0">
                                <thead>
                                    <tr>
                                        <th>耗材编码</th>
                                        <th>耗材名称</th>
                                        <th>规格</th>
                                        <th>型号</th>
                                        <th>单位</th>
                                        <th>数量</th>
                                        <th>单价</th>
                                        <th>说明</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr v-for="item in form.items">
                                        <td>{{ item.matCode }}</td>
                                        <td>{{ item.matName }}</td>
                                        <td>{{ item.specs }}</td>
                                        <td>{{ item.model }}</td>
                                        <td>{{ item.unit }}</td>
                                        <td>{{ item.num }}</td>
                                        <td>{{ item.price == null ? '' : item.price / 100 }}</td>
                                        <td>{{ item.remark }}</td>
                                    </tr>
                                </tbody>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td class="print-label-line" colspan="4">审批信息</td>
                    </tr>
                    <tr>
                        <td class="print-table-line" colspan="4">
                            <PrintFlowHistoryCpt :taskId="id"></PrintFlowHistoryCpt>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
</template>
<script>
import { ref, toRefs, reactive, onMounted } from 'vue'
import { ElNotification } from 'element-plus'
import http from '@/http.js'
import printJS from 'print-js'
import formatUtil from '@/utils/format.js'
import PrintFlowHistoryCpt from '../components/PrintFlowHistoryCpt.vue'

export default {
    props: {
        id: {
            type: String,
            default: ''
        }
    },
    components: {
        PrintFlowHistoryCpt
    },
    setup(props, ctx) {
        const state = reactive({
            form: {},
            flowList: []
        })

        const loadDetail = () => {
            http.fetchForm({
                url: '/yunying/material/findById',
                data: {
                    id: props.id
                }
            }).then((res) => {
                let data = res.data
                state.form = data
            })
        }

        const onPrint = () => {
            printJS({
                printable: 'deviceDispatchPrint',
                type: 'html',
                targetStyles: ['*'],
                style: '@page{margin-top: 1mm;margin-bottom: 1mm;}'
            })
        }

        onMounted(() => {
            loadDetail()
        })

        return {
            formatUtil,
            ...toRefs(state),
            onPrint
        }
    }
}
</script>
<style scoped>
@import '@/assets/css/print.css';
</style>
